package com.sixbro.shiro.service.rbac;

import com.sixbro.shiro.domain.entity.SysDept;
import com.sixbro.shiro.domain.entity.SysUser;
import com.sixbro.shiro.domain.vo.response.HomeResponseVO;
import com.sixbro.shiro.domain.vo.response.PermissionResponseNode;
import com.sixbro.shiro.domain.vo.response.UserInfoResponseVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @Author: Mr.Lu
 * @Since: 2020/6/19 14:28
 */
@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private UserService userService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private PermissionService permissionService;

    @Override
    public HomeResponseVO getHomeInfo(String userId) {
        SysUser sysUser = userService.detailInfo(userId);
        UserInfoResponseVO vo = new UserInfoResponseVO();

        if (sysUser != null) {
            BeanUtils.copyProperties(sysUser, vo);
            SysDept sysDept = deptService.detailInfo(sysUser.getDeptId());
            if (sysDept != null) {
                vo.setDeptId(sysDept.getId());
                vo.setDeptName(sysDept.getName());
            }
        }

        List<PermissionResponseNode> menus = permissionService.permissionTreeList(userId);

        HomeResponseVO respVO = new HomeResponseVO();
        respVO.setMenus(menus);
        respVO.setUserInfo(vo);

        return respVO;
    }
}
